/**
 * @file {目检 目标库panel表model}
 */
 'use strict'

 const {Model, DataTypes} = require('../../../azeroth').sequelize;
 const {panelInitData} = require('../common/init_data');
 class PanelMujian extends Model { }
 
 /**
  * @desc 映射需要的字段 【源库的 部分字段 --> 目标库字段】
  */
  const initPanelData = (sequelize_aim) => {
    PanelMujian.init(
         {
            uid: {
                field: 'uid',
                type: DataTypes.INTEGER,
                allowNull: false,
                primaryKey: true,
                autoIncrement: true
            },
            flaw_count: {
                field: 'flaw_count',
                type: DataTypes.INTEGER,
                allowNull: false,
                primaryKey: true,
                autoIncrement: false
            },
            panel_id: {
                field: 'panel_id',
                type: DataTypes.STRING
            },
            is_ok: {
                field: 'is_ok',
                type: DataTypes.INTEGER
            },
            length_md: {
                field: 'length_md',
                type: DataTypes.BIGINT
            },
            length_cd: {
                field: 'length_cd',
                type: DataTypes.INTEGER
            },
            checked: {
                field: 'checked',
                type: DataTypes.INTEGER
            },
            start_time: {
                field: 'start_time',
                type: DataTypes.INTEGER
            },
            start_time_str: {
                field: 'start_time_str',
                type: DataTypes.STRING
            },
            finish_time: {
                field: 'finish_time',
                type: DataTypes.INTEGER
            },
            finish_time_str: {
                field: 'finish_time_str',
                type: DataTypes.STRING
            },
            detectParam: {
                field: 'detectParam',
                type: DataTypes.TEXT
            },
         },
         {
             freezeTableName: true,
             sequelize: sequelize_aim,
             modelName: 'panel_summary',
             timestamps: false
         }
     )
  }
  PanelMujian.getPanelInfoByPanelId = async (sequelize_aim, panelId) => {
    let sql = 'select * from panel where panel_id = ' + panelId;
    let res = await sequelize_aim.query(sql, { type: sequelize_aim.QueryTypes.SELECT });
    return res[0];
  }
  /**
   * 上传panel
   * @param {Object} data 上传的panel信息对象
   * @returns
   */
  PanelMujian.uploadPolInfo = async (data) => {
    let res = await PanelMujian.bulkCreate([data], {
        updateOnDuplicate: ['uid', 'panel_id', 'flaw_count', 'is_ok', ' length_md', 'length_cd', ' save_path', ' gen_time', ' gen_time_str', 'detectParam', 'checked']
    });
    return res;
  }
 module.exports = {
     PanelMujian,
     initPanelData
 };